from typing import List


class Solution:
    def minProductSum(self, nums1: List[int], nums2: List[int]) -> int:
        nums1.sort()
        nums2.sort(reverse=True)
        return sum(nums1[i] * nums2[i] for i in range(len(nums1)))


if __name__ == "__main__":
    print(Solution().minProductSum(nums1=[5, 3, 4, 2], nums2=[4, 2, 2, 5]))  # 40
    print(Solution().minProductSum(nums1=[2, 1, 4, 5, 7], nums2=[3, 2, 4, 8, 6]))  # 65
